package com.alaoks.uploadfile.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@RestController
public class DetailController {

    @GetMapping("/detail/{dir}")
    public List<String> dirList(@PathVariable("dir") String dir){
        List<String> dirs=new ArrayList<>();
        //根目录
        String rootPath="/spb/csupload/";
        File filedir=new File(rootPath+dir);
        if(filedir.exists()&&filedir.isDirectory()){
            var fs=filedir.listFiles();
            for (File f:fs){
                if(f.isFile()){
                    dirs.add(f.getName());
                }
            }
        }else {
            filedir.mkdir();
            return new ArrayList<String>();
        }
        return  dirs;
    }
}
